const fileService = require('../service/file.service')
const { UPLOAD_PATH } = require('../config/path')
const { SERVER_HOST, SERVER_PORT } = require('../config/server')
const path = require('path')
class FileController {
	async uploadAvatar(ctx, next) {
		const { filename } = ctx.request.file
		console.log(filename)
		ctx.body = {
			code: 0,
			message: '头像上传成功',
			data: {
				tempUrl: `${SERVER_HOST}:${SERVER_PORT}/uploads/avatar/${filename}`
			}
		}
	}
	async uploadPostPicture(ctx, next) {
		try {
			const { filename } = ctx.request.file
			ctx.body = {
				errno: 0,
				data: {
					url: `${SERVER_HOST}:${SERVER_PORT}/uploads/post_picture/${filename}`
				}
			}
		} catch (err) {
			ctx.body = {
				errno: -1,
				message: '上传图片失败'
			}
		}
	}
	async uploadEventPicture(ctx, next) {
		try {
			const { filename } = ctx.request.file
			ctx.body = {
				errno: 0,
				data: {
					url: `${SERVER_HOST}:${SERVER_PORT}/uploads/event_picture/${filename}`
				}
			}
		} catch (err) {
			ctx.body = {
				errno: -1,
				message: '上传图片失败'
			}
		}
	}
}

module.exports = new FileController()
